package com.ttdj.cmel.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.ttdj.cmel.service.CMELUpdataIntentService;

public class CMELReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        switch (action) {
            case Intent.ACTION_BOOT_COMPLETED:
                break;
            case ConnectivityManager.CONNECTIVITY_ACTION:
                ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
                if (manager == null) return;
                NetworkInfo info = manager.getActiveNetworkInfo();
                if (info != null && info.isConnected()) {
                    CMELUpdataIntentService.startService(context, 1);
                }
                break;
            default:
                break;
        }
    }
}
